(function(c) {
    c.CircleEditor = function(a, b) {
        this._map = a;
        this._circle = b
    };
    c.CircleEditor.prototype = {
        open: function() {
            this._moveMarker && this._resizeMarkers || this._initMarkers();
            this._moveMarker && this._moveMarker.setMap(this._map);
            if (this._resizeMarkers) for (var a = 0, b = this._resizeMarkers.length; a < b; a++) this._resizeMarkers[a].setMap(this._map)
        },
        close: function() {
            this._moveMarker && (this._moveMarker.setMap(null), delete this._moveMarker);
            if (this._resizeMarkers) {
                for (var a = 0, b = this._resizeMarkers.length; a < b; a++) this._resizeMarkers[a].setMap(null);
                delete this._resizeMarkers
            }
        },
        _initMarkers: function() {
            this._createMoveMarker();
            this._createResizeMarker()
        },
        _createMoveMarker: function() {
            var a = this._circle.getCenter();
            this._moveMarker = this._createMarker(a)
        },
        _createResizeMarker: function() {
            var a = this._circle.getCenter(),
            a = this._getResizeMarkerPoint(a);
            this._resizeMarkers = [];
            this._resizeMarkers.push(this._createMarker(a))
        },
        _getResizeMarkerPoint: function(a) {
            var b = this._circle.getRadius() * Math.cos(Math.PI / 4);
            return a.offset(b, b)
        },
        _createMarker: function(a) {
            a = 
            new c.Marker({
                position: a,
                draggable: !0,
                icon: new c.Icon({
                    size: new c.Size(11, 11),
                    imageOffset: new c.Pixel(0, 0),
                    image: "http://webapi.amap.com/images/dd-via.png"
                }),
                offset: new c.Pixel( - 6, -6)
            });
            this._bindMarker(a);
            return a
        },
        _bindMarker: function(a) {
            a.on("dragstart", this._onMarkerDragStart, this).on("dragging", this._onMarkerDrag, this).on("dragend", this._onMarkerDragEnd, this)
        },
        _unbindMarker: function(a) {
            a.off("dragstart", this._onMarkerDragStart, this).off("dragging", this._onMarkerDrag, this).off("dragend", this._onMarkerDragEnd, 
            this)
        },
        _onMarkerDragStart: function(a) {
            a.target.hide()
        },
        _fireEdit: function() {
            this._circle.edited = !0;
            this._circle.emit("edit")
        },
        _onMarkerDrag: function(a) {
            a = a.target;
            var b = a.getPosition();
            a === this._moveMarker ? this._move(b) : this._resize(b)
        },
        _onMarkerDragEnd: function(a) {
            a.target.show();
            this._fireEdit()
        },
        _move: function(a) {
            var b = this._getResizeMarkerPoint(a);
            this._resizeMarkers[0].setPosition(b);
            this._circle.setCenter(a)
        },
        _resize: function(a) {
            a = this._moveMarker.getPosition().distance(a);
            this._circle.setRadius(a)
        }
    }
})(AMap);